package com.tueye.utils;

public class HtmlConverseUtil {
	 private static HtmlConverseUtil utile = null;
     private HtmlConverseUtil(){ 
     }
	 public static HtmlConverseUtil getInstance(){
		 if(utile == null){
			 utile = new HtmlConverseUtil();
		 }
		 return  utile;
	 }
     public  String encode(String s){   
       if(s==null){
       	return   null;   
       }  else{
         	StringBuffer sb = new StringBuffer();           
            int   n   =   s.length();   
              for (int i = 0; i < n;i++)   {
                 char   c   =   s.charAt(i);   
                 switch (c) {               
                     case ' ':   sb.append("&nbsp;");break;   
                     case '\r':  sb.append("<br/>");break;   
                     case '\'':  sb.append("&#039;");break;                           
                     case '<':   sb.append("&lt;");   break;   
                     case '>':   sb.append("&gt;");   break;   
                     case '&':   sb.append("&amp;");   break;   
                     case '"':   sb.append("&quot;");   break;                   
                     default:    sb.append(c);   
                 }   
           } 
            return   sb.toString();   
         } 
    }
}